import configparser
from sqlalchemy import Table, Column, Integer, String, Float, MetaData
from sqlalchemy import create_engine
import os, sys

class Db2Connection:
    '''''
    这个类是查找数据库的基类，封装了访问数据库的基本方法。
    '''
    conf = configparser.ConfigParser()
    conf.read(os.path.abspath(os.path.join(os.path.dirname(__file__), "./conf.ini")))
    sqlStr = conf.get("db", "dburl")
    engine = create_engine(sqlStr, echo=True, pool_size=30, max_overflow=0, pool_recycle=7200)

    @staticmethod
    def getConnection():
        return Db2Connection.engine.connect()

    @staticmethod
    def getNewEngine():
        conf = configparser.ConfigParser()
        conf.read(os.path.abspath(os.path.join(os.path.dirname(__file__), "./conf.ini")))
        sqlStr = conf.get("db", "dburl")
        engine = create_engine(sqlStr, echo=True, pool_size=8, max_overflow=0, pool_recycle=7200)
        return engine

    @staticmethod
    def getNewConnection():
        conf = configparser.ConfigParser()
        conf.read(os.path.abspath(os.path.join(os.path.dirname(__file__), "./conf.ini")))
        sqlStr = conf.get("db", "dburl")
        engine = create_engine(sqlStr, echo=True)
        return engine.connect()

    @staticmethod
    def getEngine():
        return Db2Connection.engine

    @staticmethod
    def getMemoryDbEngine():
        return create_engine("sqlite://", echo=True)

if __name__ == "__main__":
    pass
